package udf.string;

import java.io.IOException;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;

public class SplitHyphenized extends EvalFunc<Tuple> {

	public Tuple exec(Tuple input) throws IOException {

		Tuple temp = TupleFactory.getInstance().newTuple();
		String string = (String) input.get(0);
		String del = (String) input.get(1);
		Integer limit = (Integer) input.get(2);

		String t[] = string.split(del);

		if (t.length != limit) {
			return null;
		}

		temp.append(t.length);

		for (int i = 0; i < t.length; i++) {

			temp.append(t[i]);
		}

		return temp;

	}

}
